<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\common\model;

use app\common\model\VipOrder as VipOrderM;
use think\Model as ThinkModel;
use think\Db;

//银行列表模型
class ViperUser extends ThinkModel
{
    // 设置当前模型对应的完整数据表名称
    protected $table = '__QT_USER_VIPER__';
    protected $name = 'qt_user_viper';
    protected $pk = 'id';
    protected $autoWriteTimestamp = true;


    /**
     *  资金记录
     * @param  int  $uv_id   用户ID
     * @param  int  $flag    类型:  1=余额  2=积分
     * @param  int  $limit   分页条数
     * @return array
     **/
    public function viperMoneyLog($uv_id,$flag = 1,$check=1,$limit = 10)
    {
        if(!$uv_id)
        {
            return [];
        }

        $where[] = ['uv_id','eq',$uv_id];
        $where[] = ['flag','eq',$flag];
        $where[] = ['check','eq',$check];
        $list = Db::name('qt_viper_money_log')->where($where)
            ->order('id desc')
            ->paginate($limit)
            ->each(function($item){
                $check                  = $item['check'] == 1 ? '+' : '-';
                $item['money']          = $check.$item['money'];
                $item['create_time']    = date('Y-m-d H:i:s',$item['create_time']);
                return $item;
            });


        return $list->items();
    }

    /**
     *  我的团队
    **/
    public function viperTeam($store_id,$uv_id,$limit = 10)
    {
        if(!$uv_id) return [];
        $where[] = ['p_id','eq',$uv_id];
        //$where[] = ['store_id','eq',$store_id];
        $list = $this->where($where)
            ->field('id,nickname,avatar,phone')
            ->order('id desc')
            ->paginate($limit)
            ->each(function($item){
                $item['avatar'] = checkAvatar($item['avatar']);
                return $item;
            });

        return $list->items();
    }



}